#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<stdio.h>
#include<time.h>
using namespace std;

typedef struct node{
	int jiajian;
	int num1;
	int num2;
	int trytimes;
}specific;
specific informat[10];

void changesi(int p){
	if(p==0)cout<<"+";
	if(p==1)cout<<"-";
}

int getgrade(int m){
	if(m==0)return 10;
	if(m==1)return 7;
	if(m==2)return 5;
	if(m==3)return 0;
}

int suijishu(int &a,int &b,int &c,int t){
	int a1,b1;
	do{
		a1=rand()%50;
		b1=rand()%50;
	}while(!(a1+b1>=0&&a1+b1<=50&&a1-b1>=0&&a1-b1<=50));
	
	informat[t].num1=a=a1;
	informat[t].num2=b=b1;
	informat[t].jiajian=c=rand()%2;
	
	return 0;
}

void show_rank(int sum){
	cout<<endl<<endl;
	cout<<"总分："<<sum<<endl;
	if(sum>=99)cout<<"Rank:SMART"<<endl;
	else if(sum<90&&sum>=80)cout<<"Rank:GOOD"<<endl;
	else if(sum<80&&sum>=70)cout<<"Rank:OK"<<endl;
	else if(sum<70&&sum>=60)cout<<"Rank:PASS"<<endl;
	else cout<<"please TRE AGAIN"<<endl;
}

int main(){
	srand(time(NULL));
	cout<<"---------------------pupil exercrise system--------------------------";
	int t=1,cnt=0,sum=0,a,b,c,ans;
	while(t<=10){
		cout<<"this is the "<<t<<"question"<<endl;
		suijishu(a,b,c,t);
		while(cnt<=3){
			if(c==0){
				printf("%d+%d=",a,b);
				scanf("%d",&ans);
				if(a+b==ans){
					cout<<"Right"<<endl;
					break;
				}
				else{
					cnt++;
					cout<<"Wrong!!"<<endl;
					
					if(cnt==3){
						cout<<"anwser:"<<a+b<<endl;
						break;
					}
				}
			}
			else if(c==1){
				printf("%d-%d=",a,b);
				scanf("%d",&ans);
				if(a-b==ans){
					cout<<"Right"<<endl;
					break;
				}
				else{
					cnt++;
					cout<<"Wrong!!"<<endl;
					
					if(cnt==3){
						cout<<"anwser is:"<<a-b<<endl;
						break;
					}
				}
			}
		}
		informat[t].trytimes=cnt;
		if(cnt==0)sum+=10;
		if(cnt==1)sum+=7;
		if(cnt==2)sum+=5;
		t++;
		cnt=0;
		cout<<endl<<endl;
		cout<<"--------------------------------------------" <<endl;
	}
	show_rank(sum);
	cout<<endl<<endl;
	
	for(int i=1;i<=10;i++){
		cout<<"第"<<i<<"题："<<informat[i].num1;changesi(informat[i].jiajian);cout<<informat[i].num2<<"=";
		if(informat[i].jiajian==0){
			cout<<informat[i].num1+informat[i].num2<<endl;
		}
		else if(informat[i].jiajian==1){
			cout<<informat[i].num1-informat[i].num2<<endl;
			cout<<"你错了"<<informat[i].trytimes<<"次，得了"<<getgrade(informat[i].trytimes);
			cout<<"分"<<endl;
		}
	}
}
